<template>
  <div class="myContailer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>    
    </el-row>
     <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="7">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="8">
        <el-date-picker
          v-model="time"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="fuzzySearch">查 询</el-button>
      </el-col>     
    </el-row>
    
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="list"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            prop="GOODS_ID"
            width="55">
          </el-table-column>
         
          <el-table-column
            prop="GOODSNAME"
            label="商品名称"
            >          
          </el-table-column>
          
           <el-table-column
            prop="STAR_TIME"
            label="开团时间"
            >         
          </el-table-column>
          
          <el-table-column
            prop="END_TIME"
            label="闭团时间"
            >
          </el-table-column>
          
          <el-table-column
            prop="AMOUNT"
            label="剩余人数"
            >
          </el-table-column>
          
          <el-table-column
            prop="num"
            label="已参团人数"
            >
          </el-table-column>
          
          <el-table-column
            prop="STATUS"
            label="状态"
            >
              <template scope="scope">
                    <span>{{scope.row.STATUS | STATUSType}}</span>
              </template>
          </el-table-column>
                    
          <el-table-column
            label="操作"
            width="200">
            <template scope="scope">              
              <el-button type="text" @click="message(scope.row.GOODS_ID)" class="modifly" size="small">查看</el-button> 
            </template>
          </el-table-column>
       </el-table>
       
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
    
 <!--弹出框 start--> 
    <el-dialog      
       title="信息"
      :visible.sync="newDeptDialogVisible"
      >   
      <el-row class="myMarginTop_10px" :gutter="10">
      	
      <el-col :span="7">
        <el-input placeholder="请输入关键词" v-model="ORDERNO"></el-input>
      </el-col>
      <el-col :span="10">
        <el-date-picker
          v-model="dialogTime"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-col>
      <el-col :span="3">     	 
        <el-button type="primary" class="myBgGreen" @click="userquery">查 询</el-button>     
      </el-col>
      
    </el-row>
    <template>
    	 <el-row class="myMarginTop_10px">
    <el-table     
    border
    :data="listTime"
    style="width: 100%">
    <el-table-column
        prop="USER_ID"
        label="用户id"
        width="180">
      </el-table-column>
      
      <el-table-column
        prop="ORDERNO"
        label="订单号"
        width="180">
      </el-table-column>
      
      <el-table-column
        prop="ADDTIME"
        label="参团时间">
      </el-table-column>
    </el-table>
     </el-row>
  </template>               
      <div slot="footer" class="dialog-footer">
             
        <el-button type="primary" class="myBgGreen" @click="newDeptDialogVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <!--弹出框 end-->
  
  </div>
</template>

<style scoped>
  .myContailer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
</style>

<script>
	import { PRINT_API } from '@/config/baseUrl';
  import { getpurchaseUserList,purchaseDetails } from '@/api/purchaseUser';
  
  import { extractAreaIds } from '@/utils/misc';
  import { getRegion } from '@/utils/localstorage';

  export default {
    data(){
      return{  
        title:"团购用户管理",    
        list:[],  

        total:null, //总条数  
        page_num: 1, //当前页码
        page_size: 10, //每页显示多少条 
            
        listTime:[],
      
        id:null,
        index:null,
        idArr:[],
        area_id: -1,
        pages:1000,
        loading:false,
        multipleSelection: [],
        
        PRINT_API:PRINT_API,
        kw:"",
        start:"",
        end:"",
        start_o:"",
        end_o:"",
        ORDERNO:"",

        newDeptDialogVisible:false,
        time:[],
        dialogTime:[],
        s_id:""
      }
    },
    created() {
      document.title=this.title;
      this.fetchList();
    },
    
      filters: {
      STATUSType: function(value) {
        let src = '';
        switch (value) {
          case 1:
            src = '团购失败';
          break;
          case 0:
            src = '团购成功';
          break;         
        }
        return src;    
      },       
     },
     
    methods:{
       fetchList() {
        let vm = this;
        if(vm.time){
          vm.start=this.time[0];
          vm.end=this.time[1];
        }else{
          vm.start="";
          vm.end="";
        }
        const params = {
          page: vm.page_num,
          rows: vm.page_size,
          start:vm.start,
          end:vm.end,
          GOODSNAME:encodeURI(vm.kw),
          ADPLACE_ID: 4        
        }
        vm.loading = true;
        getpurchaseUserList(params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;       
          vm.loading = false;
        })
        .catch(error => {
          vm.loading = false;
        });
      },
      
      fuzzySearch() {
         this.fetchList();
      },
      
      handleSizeChange(val) {
        this.page_size = val;
        this.fetchList();
      },
      
      handleCurrentChange(val) {
        this.page_num = val;
        this.fetchList();
      },
      
      message:function(id){
      	let vm = this;  
        vm.s_id=id;
        if(vm.dialogTime){
          vm.start_o=this.dialogTime[0];
          vm.end_o=this.dialogTime[1];
        }else{
          vm.start_o="";
          vm.end_o="";
        }
      	this.newDeptDialogVisible = true;
        const data = {
           GOODS_ID:id,
           start:vm.start_o,
           end:vm.end_o,
           ORDERNO:vm.ORDERNO
        }
         let qs = require("querystring");
      	purchaseDetails(qs.stringify(data))      	
      	.then(response => {
           let res = response.data;
           vm.listTime = res.OBJECT.varList;
           console.log(res)
          //vm.loading = false;        
       })      	
      },
      userquery:function(){
          
          this.message(this.s_id)
         },
     //----页码---
      handleSelectionChange(val) {
        this.multipleSelection = val;
        if(val.length!=0){
          for(var i = 0;i<val.length;i++){
            this.idArr.push(val[i].area_id)
          }
        }else{
          this.idArr = [];
        }      
      },
      
       indexMethod(index) {
          return (this.page_num-1)*this.page_size + index + 1
      }
    }
  }
</script>



